package com.project.common.domain;

import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * jpa用户信息
 *`
 * @author ysy
 * @blame ysy
 * @date 2022-09-01
 */
@Configuration
public class UserAuditorAware implements AuditorAware<Long> {
    @Override
    public Optional<Long> getCurrentAuditor() {
        try {
            if (StpUtil.isLogin()) {
                return Optional.of(StpUtil.getLoginIdAsLong());
            }
        } catch (Exception e){

        }
        return Optional.empty();
    }
}
